package com.lv.hechuang.service;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @ClassName: MailInfoEditListenerManager
 * @Description:
 * @Author: lv
 * @Date: 2020/10/26 8:48
 */
public class MailInfoEditListenerManager {
    /**
     * 单例模式
     */
    public static MailInfoEditListenerManager listenerManager;

    /**
     * 注册的接口集合，发送广播的时候都能收到
     */
    private List<MailInfoEditListener> iListenerList = new CopyOnWriteArrayList<MailInfoEditListener>();

    public interface MailInfoEditListener {
        void mailInfoEdit(String phone);
    }

    /**
     * 获得单例对象
     */
    public static MailInfoEditListenerManager getInstance() {
        if (listenerManager == null) {
            listenerManager = new MailInfoEditListenerManager();
        }
        return listenerManager;
    }

    /**
     * 注册监听
     */
    public void registerListtener(MailInfoEditListener iListener) {
        iListenerList.add(iListener);
    }

    /**
     * 注销监听
     */
    public void unRegisterListener(MailInfoEditListener iListener) {
        iListenerList.clear();
    }

    /**
     * 发送广播
     */
    public void sendBroadCast(String msgNo) {
        for (MailInfoEditListener iListener : iListenerList) {
            iListener.mailInfoEdit(msgNo);
        }
    }
}
